<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>申报任务申报</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="/lib/jquery-2.1.4.min.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/baseCode/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/sys/citys.js" type="text/javascript" charset="utf-8"></script>

</head>
<style>
    .mbox {
        padding: 8px;
        background: #fff;
    }

    .btn {
        height: 30px;
    }

    .btn button {
        float: right;
    }

    .red_12_normal {
        color: red;
    }

    .form {
        font-size: 9pt;
    }

    .form tr {
        height: 60px;
        line-height: 60px;
    }

    .form th {
        position: relative;
        padding-left: 10px;
        text-align: left;
        white-space: nowrap;
        font-weight: normal;
        width: 90px;
        padding-right: 1px;
    }

    .choice, .empty {
        margin-left: 5px;
    }

    .empty {
        color: red;
    }

    .choice {
        color: blue;
    }
    /* 防止下拉框的下拉列表被隐藏---必须设置--- */
    /*.layui-table-cell {                }*/
    .layui-table-cell {
        height:auto;
    }
    #tem1 td[data-field="trOther"] .layui-table-cell,
    #tem2 td[data-field="trOther"] .layui-table-cell,
    #tem3 td[data-field="trOther"] .layui-table-cell,
    #tem4 td[data-field="trOther"] .layui-table-cell,
    #tem5 td[data-field="trOther"] .layui-table-cell{
        overflow: visible !important;
    }
    #tem1 td[data-field="type"] .layui-table-cell,
    #tem2 td[data-field="type"] .layui-table-cell,
    #tem3 td[data-field="type"] .layui-table-cell,
    #tem4 td[data-field="type"] .layui-table-cell,
    #tem5 td[data-field="type"] .layui-table-cell{
        overflow: visible !important;
    }
    #tem4 td[data-field="trOther2"] .layui-table-cell,
    #tem5 td[data-field="trOther2"] .layui-table-cell,
    #tem4 td[data-field="trOther3"] .layui-table-cell,
    #tem5 td[data-field="trOther3"] .layui-table-cell{
        overflow: visible !important;
    }
    #tableBox .layui-table-cell .layui-form-checkbox[lay-skin=primary] {
        top: 0px!important;
    }
    #tableBox .layui-table-cell .layui-form-select {
        top: 5px!important;
    }
    /* 使得下拉框与单元格刚好合适 */
    td .layui-form-select{
        margin-top: -10px;
        margin-left: -15px;
        margin-right: -15px;
    }
    #form_basic td .layui-form-select{
        margin: 0
    }
    #budgetForm td .layui-form-select{
        margin: 0
    }
    /*解决下拉框被表格覆盖样式问题*/
    .layui-form-select dl {
        z-index: 9999;
    }
    .layui-table-box {
        overflow: visible
    }
    .layui-table-body{
        overflow:visible;
    }
    .floatDiv > div:hover {
        background-color: #6ea1d5;
        color: #ffffff;
    }

    .floatDiv > div {
        height: 35px;
        width: 100%;
        line-height: 29px;
        text-align: center;
        cursor: pointer;
    }

    .floatDiv {
        position: fixed;
        border: #ccc 1px solid;
        border-radius: 4px;
        background-color: #ffffff;
        z-index: 99;
    }
    .wordText{
        width: 80%;
        position: absolute;
        font-size: 14px;
        left: 45px;
        margin-top: 15px;
        z-index: 5555;
    }
</style>
<body>
<div class="mbox">
    <div class="btn">
        <button type="button" class="layui-btn layui-btn-sm comeback">返回
        </button>
    </div>
    <div class="layui-tab layui-tab-card" lay-filter="edittabbar">
        <ul class="layui-tab-title">
            <li num="1" class="layui-this" id="base">基本信息</li>
            <li num="2">学术著作</li>
            <li num="3">学术论文</li>
            <li num="4">学术论坛主题发言</li>
            <li num="5">结题成果</li>
            <li num="6" id="yuqi">评选获奖</li>
        </ul>
        <div class="layui-tab-content"id="tableBox">
            <div class="layui-tab-item layui-show">
                <form class="layui-form" id="form_basic">
                    <div class="layui-form-item">
                        <label class="layui-form-label">科室:</label>
                        <div class="layui-input-block">
                            <input type="text" name="deptId" disabled="" id="deptId"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名:</label>
                        <div class="layui-input-block">
                            <input type="text" name="userId" disabled=""id="userIdUser" user_id="" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备案时间:</label>
                        <div class="layui-input-block">
                            <input type="text" name="filingTime" disabled=""id="filingTime" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-tab-item">
                <div class="wordText">学术著作:指正规出版社公开出版，且取得正式书号的学术著作。主要包括专著、编著、译著等，按个人参与的部分可分为独立著作权、主编、参编（有署名或著作中编写说明中提及）。</div>
                <table class="layui-table" id="participator" lay-filter="participator"></table>
            </div>
            <div class="layui-tab-item">
                <div class="wordText">学术论文:指由正规学术刊物公开发表的署名学术论文。</div>
                <table class="layui-hide" id="academic" lay-filter="academic"></table>
            </div>
            <div class="layui-tab-item">
                <div class="wordText">学术论坛主题发言:指在全区及以上层面专业学术论坛上公开交流的学术材料。</div>
                <table class="layui-hide" id="achievement" lay-filter="achievement"></table>
            </div>
            <div class="layui-tab-item">
                <div class="wordText">结题成果:指已结题的区级及以上各类课题研究成果。</div>
                <table class="layui-hide" id="task" lay-filter="task"></table>
            </div>
            <div class="layui-tab-item">
                <div class="wordText">评选获奖:指各专业条线组织的区级及以上层面各类评选获奖成果。</div>
                <table class="layui-hide" id="expect" lay-filter="expect"></table>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/html" id="xuhao">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script>
    var parName = [];
    var deptId=$.cookie('deptId');
    var model="resultsManagement";
    var create_type=3;
    var topicId;
    var flag=0;
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);

        if (r != null) {
            return unescape(r[2]);
        } else {
            return null;
        }
    }
    var planId=GetQueryString('planId');
    var userId=GetQueryString('userId');
    $('.layui-tab-content').height($(window).height() - 130);

    layui.use(['table', 'form', 'laydate', 'upload', 'element'], function () {
        var table = layui.table,
            form = layui.form,
            laydate = layui.laydate,
            upload = layui.upload
        var element = layui.element;
        //年范围
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#startingEndingTime'
        });
        laydate.render({
            elem: '#completionTime'
        });
        $('.comeback').click(function(){
            window.location.href='/Results/achievementIdentification'
        })
        var academicLevelSel,conclusionLevelSel,keynoteAddressLevelSel,selectionLevelSel,thesisLevelSel,conclusionLevelPriv;
        form.render()

        $.ajax({
            url: '/rpmTopic/getDictionary',
            type: 'get',
            dataType: 'json',
            async:false,
            success: function (res) {
                academicLevelSel=res.object.academicLevel
                conclusionLevelSel=res.object.conclusionLevel
                keynoteAddressLevelSel=res.object.keynoteAddressLevel
                selectionLevelSel=res.object.selectionLevel
                thesisLevelSel=res.object.thesisLevel
                conclusionLevelPriv=res.object.conclusionLevelPriv
            }
        })
        $.ajax({
            url: '/rpmTopic/selectgetTopicId',
            data:{
                planId: GetQueryString('planId'),
                userId: userId
            },
            type: 'post',
            dataType: 'json',
            success: function (res) {
                if (res.code==0) {
                    if(res.object != undefined) {
                        topicId = res.object.rpmTopic.topicId
                        var rpmTopic = res.object.rpmTopic
                        $('.add').attr('topicId', res.object.rpmTopic.topicId)


                        $('[name="userId"]').val(rpmTopic.userName)
                        $('[name="deptId"]').val(rpmTopic.deptName)
                        $('[name="filingTime"]').val(rpmTopic.filingTime)
                        tableDatas();
                    }else{
                        if (topicId == undefined) {
                            var arr = [];
                            $.ajax({
                                url: '/rpmTopic/getDeptByIdPlus?deptId='+deptId,
                                type: 'get',
                                dataType: 'json',
                                async:false,
                                success: function (res) {
                                    $('[name="deptId"]').val(res.object.deptName)
                                }
                            })
                            $('#userIdUser').val($.cookie('userName'))
                            $('#userIdUser').attr("user_id", userId)
                            $("#filingTime").val(nowformat);
                            tableData(arr,'participator')
                            tableData(arr,'academic')
                            tableData(arr,'achievement')
                            tableData(arr,'task')
                            tableData(arr,'expect')
                        }
                    }
                } else {
                }
            }
        })
        $('#chargetype').siblings('.layui-form-select').hide()
        function tableDatas() {
            // 学术著作
            participatorTable=table.render({
                elem: '#participator'
                ,url:'/rpmTopic/selectgetTopicId?planId='+GetQueryString('planId')+'&userId='+userId
                , toolbar: '#toolbarDemo'
                , defaultToolbar: ['']
                , title: '学术著作'
                , cols: [[
                    {field: 'topicId', hide: true}
                    ,{field: 'numbers', title: '序号',templet: '#xuhao',width:60}
                    , {field: 'trOther', title: '级别',templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<academicLevelSel.length;i++){
                                str+='<option value="'+academicLevelSel[i].dictNo+'">'+academicLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                        }}
                    , {field: 'trOther2', title: '成果名称'}
                    , {field: 'trOther3', title: '出版单位'}
                    , {
                        field: 'trTime',
                        title: '出版时间',
                        event: 'trTime',
                        data_field: "trTime"
                    }
                    , {field: 'trOther4', title: '备注'}
                    , {
                        field: 'attachmentName',  width:270,title: '附件著作（原件）上传',
                        templet:
                            function (d) {
                                var attachmentIds = d.attachmentId;
                                var attachmentNames = d.attachmentName;
                                if (attachmentNames != undefined && attachmentNames.length > 0) {
                                    var attachIdArray = "";
                                    if (attachmentIds != undefined) {
                                        attachIdArray = attachmentIds.split(",")
                                    }
                                    var attachNameArray = attachmentNames.split(",")
                                    var $as = "";
                                    for (var i = 0; i < attachNameArray.length; i++) {
                                        var attachId = "";
                                        if (i < attachIdArray.length) {
                                            attachId = attachIdArray[i];
                                        }
                                        var attachName = attachNameArray[i];
                                        var c = "";
                                        if (i > 0) {
                                            c = ",";
                                        }
                                        if (attachName != "") {
                                            $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                        }

                                    }
                                    return '<div>' + $as + '</div>'
                                } else {
                                    return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                }
                            }
                    }
                ]]
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.object.rpmTopicRemarkWithBLOBs//解析数据列表
                    };
                }
                , done: function (obj) {
                    $("select").attr("disabled","disabled");
                    $("[data-field='trTime']").attr("disabled","disabled");
                    form.on('select(trOther)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther=pr.value;
                    });

                    var data=obj.data;
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    //添加查阅下载
                    $(".aUploadFile").each(function (i) {
                        var attchId = $(this).attr("attachId");
                        var attchName = $(this).attr("attachName");
                        var div = '<div class="floatDiv" tableName="participator" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        $(this).after(div);
                    })
                    form.render()
                }
            });
            // 学术论文
            academicTable=table.render({
                elem: '#academic'
                ,url:'/rpmTopic/selectgetTopicId?planId='+GetQueryString('planId')+'&userId='+userId
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['']
                , title: '学术论文'
                , cols: [[
                     {field: 'topicId', hide: true}
                    , {field: 'numbers', title: '序号',templet: '#xuhao',width:60}
                    , {field: 'trOther', title: '级别',templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<thesisLevelSel.length;i++){
                                str+='<option value="'+thesisLevelSel[i].dictNo+'">'+thesisLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                        }}
                    , {field: 'trOther2', title: '成果名称'}
                    , {field: 'trOther3', title: '发表刊物'}
                    , {
                        field: 'trTime',
                        edit:false,
                        title: '发表时间',
                        event: 'trTime',
                        data_field: "trTime"
                    }
                    , {field: 'trOther4', title: '备注'}
                    , {
                        field: 'attachmentName',  width:270,title: '附件刊物封面、目录页及论文，各一份',
                        templet:
                            function (d) {
                                var attachmentIds = d.attachmentId;
                                var attachmentNames = d.attachmentName;
                                if (attachmentNames != undefined && attachmentNames.length > 0) {
                                    var attachIdArray = "";
                                    if (attachmentIds != undefined) {
                                        attachIdArray = attachmentIds.split(",")
                                    }
                                    var attachNameArray = attachmentNames.split(",")
                                    var $as = "";
                                    for (var i = 0; i < attachNameArray.length; i++) {
                                        var attachId = "";
                                        if (i < attachIdArray.length) {
                                            attachId = attachIdArray[i];
                                        }
                                        var attachName = attachNameArray[i];
                                        var c = "";
                                        if (i > 0) {
                                            c = ",";
                                        }
                                        if (attachName != "") {
                                            $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                        }

                                    }
                                    return '<div>' + $as + '</div>'
                                } else {
                                    return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                }
                            }
                    }
                ]]
                // , page: true
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.object.rpmTopicRemarkWithBLOBs1 //解析数据列表
                    };
                }
                , done: function (obj) {
                    $("select").attr("disabled","disabled");
                    var data=obj.data;
                    form.on('select(trOther)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther=pr.value;
                    });

                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                        });
                    }
                    form.render()
                    //添加查阅下载
                    $(".aUploadFile").each(function (i) {
                        var attchId = $(this).attr("attachId");
                        var attchName = $(this).attr("attachName");
                        var div = '<div class="floatDiv" tableName="academic" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        $(this).after(div);
                    })
                    form.render()
                }
            });
            // 学术论坛主题发言
            achievementTable=table.render({
                elem: '#achievement'
                ,url:'/rpmTopic/selectgetTopicId?planId='+GetQueryString('planId')+'&userId='+userId
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['']
                , title: '学术论坛主题发言'
                // , page: true
                , cols: [[
                    {field: 'topicId', hide: true}
                    ,{field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                    , {field: 'trOther', title: '级别',templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<keynoteAddressLevelSel.length;i++){
                                str+='<option value="'+keynoteAddressLevelSel[i].dictNo+'">'+keynoteAddressLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                        }}
                    , {field: 'trOther2', title: '成果名称'}
                    , {field: 'trOther3', title: '学术论坛名称'}
                    , {
                        field: 'trTime',
                        title: '交流时间',
                        event: 'trTime',
                        data_field: "trTime"
                    }
                    , {field: 'trOther4', title: '备注'}
                    , {
                        field: 'attachmentName',  width:300,title: '附件发言交流材料；交流证明，各一份',
                        templet:
                            function (d) {
                                var attachmentIds = d.attachmentId;
                                var attachmentNames = d.attachmentName;
                                if (attachmentNames != undefined && attachmentNames.length > 0) {
                                    var attachIdArray = "";
                                    if (attachmentIds != undefined) {
                                        attachIdArray = attachmentIds.split(",")
                                    }
                                    var attachNameArray = attachmentNames.split(",")
                                    var $as = "";
                                    for (var i = 0; i < attachNameArray.length; i++) {
                                        var attachId = "";
                                        if (i < attachIdArray.length) {
                                            attachId = attachIdArray[i];
                                        }
                                        var attachName = attachNameArray[i];
                                        var c = "";
                                        if (i > 0) {
                                            c = ",";
                                        }
                                        if (attachName != "") {
                                            $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                        }

                                    }
                                    return '<div>' + $as + '</div>'
                                } else {
                                    return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                }
                            }
                    }
                ]]
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.object.rpmTopicRemarkWithBLOBs2 //解析数据列表
                    };
                }
                ,done:function(obj){
                    var data=obj.data;
                    form.on('select(trOther)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                        });
                    }
                    form.render()
                    //添加查阅下载
                    $(".aUploadFile").each(function (i) {
                        var attchId = $(this).attr("attachId");
                        var attchName = $(this).attr("attachName");
                        var div = '<div class="floatDiv" tableName="achievement" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        $(this).after(div);
                    })
                }
            });
            // 结题成果
            taskTable=table.render({
                elem: '#task'
                ,url:'/rpmTopic/selectgetTopicId?planId='+GetQueryString('planId')+'&userId='+userId
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['']
                , title: '结题成果'
                , cols: [[
                     {field: 'topicId', hide: true}
                    , {field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                    , {field: 'trOther', title: '部级及以上',width:90,templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<conclusionLevelSel.length;i++){
                                str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                        }}
                    , {field: 'trOther2', title: '市区重点',templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<conclusionLevelSel.length;i++){
                                str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther2" lay-filter="trOther2" >'+str+'</select>'
                        }}
                    , {field: 'trOther3', title: '区级其他',templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<conclusionLevelSel.length;i++){
                                str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther3" lay-filter="trOther3" >'+str+'</select>'
                        }}
                    , {
                        field: 'trTime',
                        title: '结题时间',
                        event: 'trTime',
                        data_field: "trTime"
                    }
                    , {field: 'trOther4', title: '角色'}
                    , {field: 'trOther5', title: '课题名称'}
                    , {field: 'trOther6', title: '批准单位'}
                    , {field: 'trOther7', title: '备注'}
                    , {
                        field: 'attachmentName',  width:290,title: '附件结题证书、成果鉴定等第证明',
                        templet:
                            function (d) {
                                var attachmentIds = d.attachmentId;
                                var attachmentNames = d.attachmentName;
                                if (attachmentNames != undefined && attachmentNames.length > 0) {
                                    var attachIdArray = "";
                                    if (attachmentIds != undefined) {
                                        attachIdArray = attachmentIds.split(",")
                                    }
                                    var attachNameArray = attachmentNames.split(",")
                                    var $as = "";
                                    for (var i = 0; i < attachNameArray.length; i++) {
                                        var attachId = "";
                                        if (i < attachIdArray.length) {
                                            attachId = attachIdArray[i];
                                        }
                                        var attachName = attachNameArray[i];
                                        var c = "";
                                        if (i > 0) {
                                            c = ",";
                                        }
                                        if (attachName != "") {
                                            $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                        }
                                    }
                                    return '<div>' + $as + '</div>'
                                } else {
                                    return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                }
                            }
                    }
                ]]
                // , page: true
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.object.rpmTopicRemarkWithBLOBs3 //解析数据列表
                    };
                }
                ,done:function (obj) {
                    $("select").attr("disabled","disabled");
                    var data=obj.data;
                    form.on('select(trOther)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    form.on('select(trOther2)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther2=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther2']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther2 + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    form.on('select(trOther3)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther3=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther3']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther3 + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    form.on('select(trOther4)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther4=pr.value;
                    });
                    form.render()
                    //添加查阅下载
                    $(".aUploadFile").each(function (i) {
                        var attchId = $(this).attr("attachId");
                        var attchName = $(this).attr("attachName");
                        var div = '<div class="floatDiv" tableName="task" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        $(this).after(div);
                    })
                }
            });
            // 评选获奖
            expectTable=table.render({
                elem: '#expect'
                ,url:'/rpmTopic/selectgetTopicId?planId='+GetQueryString('planId')+'&userId='+userId
                , data: function () {
                    if (expect != ''||expect.length == 0) {
                        return expect
                    } else {
                        return [{topicId: topicId}]
                    }
                }()
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['']
                , title: '评选获奖'
                , cols: [[
                    {field: 'topicId', hide: true}
                    , {field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                    , {field: 'trOther', title: '部级及以上',width:90,templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<selectionLevelSel.length;i++){
                                str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                        }}
                    , {field: 'trOther2', title: '市级(区重点)',width:100,templet:function () {
                            var str='<option>请选择</option>'
                            for(var i=0;i<selectionLevelSel.length;i++){
                                str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther2" lay-filter="trOther2" >'+str+'</select>'
                        }}
                    , {
                        field: 'trOther3', title: '区级其他', templet: function (obj) {
                            var str='<option>请选择</option>'
                            for(var i=0;i<selectionLevelSel.length;i++){
                                str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                            }
                            return ' <select name="trOther3" lay-filter="trOther3" >'+str+'</select>'
                        }
                    }
                    , {field: 'trOther4', title: '成果名称'}
                    , {field: 'trOther5', title: '成果评审主办单位',width:160}
                    , {field: 'trOther6', title: '备注'}
                    , {
                        field: 'attachmentName',  width:276,title: '附件获奖证明一份',
                        templet:
                            function (d) {
                                var attachmentIds = d.attachmentId;
                                var attachmentNames = d.attachmentName;
                                if (attachmentNames != undefined && attachmentNames.length > 0) {
                                    var attachIdArray = "";
                                    if (attachmentIds != undefined) {
                                        attachIdArray = attachmentIds.split(",")
                                    }
                                    var attachNameArray = attachmentNames.split(",")
                                    var $as = "";
                                    for (var i = 0; i < attachNameArray.length; i++) {
                                        var attachId = "";
                                        if (i < attachIdArray.length) {
                                            attachId = attachIdArray[i];
                                        }
                                        var attachName = attachNameArray[i];
                                        var c = "";
                                        if (i > 0) {
                                            c = ",";
                                        }
                                        if (attachName != "") {
                                            $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                        }

                                    }
                                    return '<div>' + $as + '</div>'
                                } else {
                                    return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                }
                            }
                    }
                ]]
                // , page: true
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": 0, //解析接口状态
                        "data": res.object.rpmTopicRemarkWithBLOBs4 //解析数据列表
                    };
                }
                , done: function (obj) {
                    $("select").attr("disabled","disabled");
                    var data=obj.data;
                    form.on('select(trOther)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                        });
                    }
                    form.on('select(trOther2)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther2=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther2']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther2 + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    form.on('select(trOther3)', function(pr){
                        var dataindex=$(pr.elem).parents('tr').attr("data-index");
                        data[dataindex].trOther3=pr.value;
                    });
                    var selectId = $(this.elem[0].nextElementSibling)
                        , mineSelparentTyepNo = $(selectId).find("select[name='trOther3']")
                    for (var i = 0; i < obj.data.length; i++) {
                        layui.each(mineSelparentTyepNo, function (index, item) {
                            if (index == i) $(item).find('option[value="' + obj.data[i].trOther3 + '"]').prop('selected', 'selected');
                            // $(item).attr('disabled', 'disabled').attr('dataType', '1')
                        });
                    }
                    form.render()
                    //添加查阅下载
                    $(".aUploadFile").each(function (i) {
                        var attchId = $(this).attr("attachId");
                        var attchName = $(this).attr("attachName");
                        var div = '<div class="floatDiv" tableName="expect" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        $(this).after(div);
                    })
                }
            });
        }
        function tableData(data,id) {
            if(id=='participator'){
                // 学术著作
                participatorTable = table.render({
                    elem: '#participator'
                    , data:data
                    , toolbar: '#toolbarDemo'
                    , defaultToolbar: ['']
                    , title: '学术著作'
                    , cols: [[
                        {field: 'topicId', hide: true}
                        ,{field: 'numbers', title: '序号',templet: '#xuhao',width:60}
                        , {field: 'trOther', title: '级别',templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<academicLevelSel.length;i++){
                                    str+='<option value="'+academicLevelSel[i].dictNo+'">'+academicLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                            }}
                        , {field: 'trOther2', title: '成果名称'}
                        , {field: 'trOther3', title: '出版单位'}
                        , {
                            field: 'trTime',
                            title: '出版时间',
                            event: 'trTime',
                            data_field: "trTime"
                        }
                        , {field: 'trOther4', title: '备注'}
                        , {
                            field: 'attachmentName',  width:270,title: '附件著作（原件）上传',
                            templet:
                                function (d) {
                                    var attachmentIds = d.attachmentId;
                                    var attachmentNames = d.attachmentName;
                                    if (attachmentNames != undefined && attachmentNames.length > 0) {
                                        var attachIdArray = "";
                                        if (attachmentIds != undefined) {
                                            attachIdArray = attachmentIds.split(",")
                                        }
                                        var attachNameArray = attachmentNames.split(",")
                                        var $as = "";
                                        for (var i = 0; i < attachNameArray.length; i++) {
                                            var attachId = "";
                                            if (i < attachIdArray.length) {
                                                attachId = attachIdArray[i];
                                            }
                                            var attachName = attachNameArray[i];
                                            var c = "";
                                            if (i > 0) {
                                                c = ",";
                                            }
                                            if (attachName != "") {
                                                $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                            }

                                        }
                                        return '<div>' + $as + '</div>'
                                    } else {
                                        return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                    }
                                }
                        }
                    ]]
                    , page: true
                    , done: function (obj) {

                        form.on('select(trOther)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther=pr.value;
                        });
                        var data=obj.data;
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            });
                        }

                        //添加查阅下载
                        $(".aUploadFile").each(function (i) {
                            var attchId = $(this).attr("attachId");
                            var attchName = $(this).attr("attachName");
                            var div = '<div class="floatDiv" tableName="participator" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                            $(this).after(div);
                        })
                        form.render()
                    }
                });
            }else if(id=='academic'){
                // 学术论文
                academicTable = table.render({
                    elem: '#academic'
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , data: data
                    , defaultToolbar: ['']
                    , title: '学术论文'
                    , cols: [[
                         {field: 'topicId', hide: true}
                        , {field: 'numbers', title: '序号',templet: '#xuhao',width:60}
                        , {field: 'trOther', title: '级别',templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<thesisLevelSel.length;i++){
                                    str+='<option value="'+thesisLevelSel[i].dictNo+'">'+thesisLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                            }}
                        , {field: 'trOther2', title: '成果名称'}
                        , {field: 'trOther3', title: '发表刊物'}
                        , {
                            field: 'trTime',
                            edit:false,
                            title: '发表时间',
                            event: 'trTime',
                            data_field: "trTime"
                        }
                        , {field: 'trOther4', title: '备注'}
                        , {
                            field: 'attachmentName',  width:270,title: '附件刊物封面、目录页及论文，各一份',
                            templet:
                                function (d) {
                                    var attachmentIds = d.attachmentId;
                                    var attachmentNames = d.attachmentName;
                                    if (attachmentNames != undefined && attachmentNames.length > 0) {
                                        var attachIdArray = "";
                                        if (attachmentIds != undefined) {
                                            attachIdArray = attachmentIds.split(",")
                                        }
                                        var attachNameArray = attachmentNames.split(",")
                                        var $as = "";
                                        for (var i = 0; i < attachNameArray.length; i++) {
                                            var attachId = "";
                                            if (i < attachIdArray.length) {
                                                attachId = attachIdArray[i];
                                            }
                                            var attachName = attachNameArray[i];
                                            var c = "";
                                            if (i > 0) {
                                                c = ",";
                                            }
                                            if (attachName != "") {
                                                $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                            }

                                        }
                                        return '<div>' + $as + '</div>'
                                    } else {
                                        return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                    }
                                }
                        }
                    ]]
                    , page: true
                    , done: function (obj) {
                        $("select").attr("disabled","disabled");
                        var data=obj.data;
                        form.on('select(trOther)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther=pr.value;
                        });

                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            });
                        }
                        form.render()
                        //添加查阅下载
                        $(".aUploadFile").each(function (i) {
                            var attchId = $(this).attr("attachId");
                            var attchName = $(this).attr("attachName");
                            var div = '<div class="floatDiv" tableName="academic" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                            $(this).after(div);
                        })
                        form.render()
                    }
                });
            }else if(id=='achievement'){
                // 学术论坛主题发言
                achievementTable = table.render({
                    elem: '#achievement'
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , data: data
                    , defaultToolbar: ['']
                    , title: '学术论坛主题发言'
                    , page: true
                    , cols: [[
                         {field: 'topicId', hide: true}
                        ,{field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                        , {field: 'trOther', title: '级别',templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<keynoteAddressLevelSel.length;i++){
                                    str+='<option value="'+keynoteAddressLevelSel[i].dictNo+'">'+keynoteAddressLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                            }}
                        , {field: 'trOther2', title: '成果名称'}
                        , {field: 'trOther3', title: '学术论坛名称'}
                        , {
                            field: 'trTime',
                            title: '交流时间',
                            event: 'trTime',
                            data_field: "trTime"
                        }
                        , {field: 'trOther4', title: '备注'}
                        , {
                            field: 'attachmentName',  width:300,title: '附件发言交流材料；交流证明，各一份',
                            templet:
                                function (d) {
                                    var attachmentIds = d.attachmentId;
                                    var attachmentNames = d.attachmentName;
                                    if (attachmentNames != undefined && attachmentNames.length > 0) {
                                        var attachIdArray = "";
                                        if (attachmentIds != undefined) {
                                            attachIdArray = attachmentIds.split(",")
                                        }
                                        var attachNameArray = attachmentNames.split(",")
                                        var $as = "";
                                        for (var i = 0; i < attachNameArray.length; i++) {
                                            var attachId = "";
                                            if (i < attachIdArray.length) {
                                                attachId = attachIdArray[i];
                                            }
                                            var attachName = attachNameArray[i];
                                            var c = "";
                                            if (i > 0) {
                                                c = ",";
                                            }
                                            if (attachName != "") {
                                                $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                            }

                                        }
                                        return '<div>' + $as + '</div>'
                                    } else {
                                        return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                    }
                                }
                        }
                    ]]
                    ,done:function(obj){
                        $("select").attr("disabled","disabled");
                        $(".show3").css('display','block')
                        var data=obj.data;
                        form.on('select(trOther)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther=pr.value;
                        });

                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            });
                        }
                        form.render()
                        //添加查阅下载
                        $(".aUploadFile").each(function (i) {
                            var attchId = $(this).attr("attachId");
                            var attchName = $(this).attr("attachName");
                            var div = '<div class="floatDiv" tableName="achievement" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                            $(this).after(div);
                        })
                    }
                });
            }else if(id=='task'){
                // 结题成果
                taskTable = table.render({
                    elem: '#task'
                    , data:data
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , defaultToolbar: ['']
                    , title: '结题成果'
                    , cols: [[
                        {field: 'topicId', hide: true}
                        , {field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                        , {field: 'trOther', title: '部级及以上',width:90,templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<conclusionLevelSel.length;i++){
                                    str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                            }}
                        , {field: 'trOther2', title: '市区重点',templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<conclusionLevelSel.length;i++){
                                    str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther2" lay-filter="trOther2" >'+str+'</select>'
                            }}
                        , {field: 'trOther3', title: '区级其他',templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<conclusionLevelSel.length;i++){
                                    str+='<option value="'+conclusionLevelSel[i].dictNo+'">'+conclusionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther3" lay-filter="trOther3" >'+str+'</select>'
                            }}
                        , {
                            field: 'trTime',
                            title: '结题时间',
                            event: 'trTime',
                            data_field: "trTime"
                        }
                        , {field: 'trOther4', title: '角色'}
                        , {field: 'trOther5', title: '课题名称'}
                        , {field: 'trOther6', title: '批准单位'}
                        , {field: 'trOther7', title: '备注'}
                        , {
                            field: 'attachmentName',  width:290,title: '附件结题证书、成果鉴定等第证明',
                            templet:
                                function (d) {
                                    var attachmentIds = d.attachmentId;
                                    var attachmentNames = d.attachmentName;
                                    if (attachmentNames != undefined && attachmentNames.length > 0) {
                                        var attachIdArray = "";
                                        if (attachmentIds != undefined) {
                                            attachIdArray = attachmentIds.split(",")
                                        }
                                        var attachNameArray = attachmentNames.split(",")
                                        var $as = "";
                                        for (var i = 0; i < attachNameArray.length; i++) {
                                            var attachId = "";
                                            if (i < attachIdArray.length) {
                                                attachId = attachIdArray[i];
                                            }
                                            var attachName = attachNameArray[i];
                                            var c = "";
                                            if (i > 0) {
                                                c = ",";
                                            }
                                            if (attachName != "") {
                                                $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                            }
                                        }
                                        return '<div>' + $as + '</div>'
                                    } else {
                                        return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                    }
                                }
                        }
                    ]]
                    , page: true
                    ,done:function (obj) {
                        $("select").attr("disabled","disabled");
                        $(".show4").css('display','block')
                        var data=obj.data;
                        form.on('select(trOther)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            });
                        }
                        form.on('select(trOther2)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther2=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther2']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther2 + '"]').prop('selected', 'selected');
                            });
                        }
                        form.on('select(trOther3)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther3=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther3']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther3 + '"]').prop('selected', 'selected');
                            });
                        }
                        form.on('select(trOther4)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther4=pr.value;
                        });
                        form.render()
                        //添加查阅下载
                        $(".aUploadFile").each(function (i) {
                            var attchId = $(this).attr("attachId");
                            var attchName = $(this).attr("attachName");
                            var div = '<div class="floatDiv" tableName="task" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                            $(this).after(div);
                        })
                    }
                });
            }else if(id=='expect'){
                // 评选获奖
                expectTable = table.render({
                    elem: '#expect'
                    , data: data
                    , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                    , defaultToolbar: ['']
                    , title: '评选获奖'
                    , cols: [[
                         {field: 'topicId', hide: true}
                        , {field: 'numbers', title: '序号',templet: '#xuhao',width:70}
                        , {field: 'trOther', title: '部级及以上',width:90,templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<selectionLevelSel.length;i++){
                                    str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther" lay-filter="trOther" >'+str+'</select>'
                            }}
                        , {field: 'trOther2', title: '市级(区重点)',width:100,templet:function () {
                                var str='<option>请选择</option>'
                                for(var i=0;i<selectionLevelSel.length;i++){
                                    str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther2" lay-filter="trOther2" >'+str+'</select>'
                            }}
                        , {
                            field: 'trOther3', title: '区级其他', templet: function (obj) {
                                var str='<option>请选择</option>'
                                for(var i=0;i<selectionLevelSel.length;i++){
                                    str+='<option value="'+selectionLevelSel[i].dictNo+'">'+selectionLevelSel[i].dictName+'</option>'
                                }
                                return ' <select name="trOther3" lay-filter="trOther3" >'+str+'</select>'
                            }
                        }
                        , {field: 'trOther4', title: '成果名称'}
                        , {field: 'trOther5', title: '成果评审主办单位',width:160}
                        , {field: 'trOther6', title: '备注'}
                        , {
                            field: 'attachmentName',  width:276,title: '附件获奖证明一份',
                            templet:
                                function (d) {
                                    var attachmentIds = d.attachmentId;
                                    var attachmentNames = d.attachmentName;
                                    if (attachmentNames != undefined && attachmentNames.length > 0) {
                                        var attachIdArray = "";
                                        if (attachmentIds != undefined) {
                                            attachIdArray = attachmentIds.split(",")
                                        }
                                        var attachNameArray = attachmentNames.split(",")
                                        var $as = "";
                                        for (var i = 0; i < attachNameArray.length; i++) {
                                            var attachId = "";
                                            if (i < attachIdArray.length) {
                                                attachId = attachIdArray[i];
                                            }
                                            var attachName = attachNameArray[i];
                                            var c = "";
                                            if (i > 0) {
                                                c = ",";
                                            }
                                            if (attachName != "") {
                                                $as += '<a href="javascript:;" attachName="' + attachName + '" attachId="' + attachId + '"  class="layui-table-link">' + "【" + attachName + "】" + '</a><br/>'
                                            }

                                        }
                                        return '<div>' + $as + '</div>'
                                    } else {
                                        return '<div><a href="javascript:;" class="layui-table-link">' + "" + '</a></div>'
                                    }
                                }
                        }
                    ]]
                    , page: true
                    , done: function (obj) {
                        $("select").attr("disabled","disabled");
                        $(".show5").css('display','block')
                        var data=obj.data;
                        form.on('select(trOther)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther + '"]').prop('selected', 'selected');
                            });
                        }
                        form.on('select(trOther2)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther2=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther2']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther2 + '"]').prop('selected', 'selected');
                            });
                        }
                        form.on('select(trOther3)', function(pr){
                            var dataindex=$(pr.elem).parents('tr').attr("data-index");
                            data[dataindex].trOther3=pr.value;
                        });
                        var selectId = $(this.elem[0].nextElementSibling)
                            , mineSelparentTyepNo = $(selectId).find("select[name='trOther3']")
                        for (var i = 0; i < obj.data.length; i++) {
                            layui.each(mineSelparentTyepNo, function (index, item) {
                                if (index == i) $(item).find('option[value="' + obj.data[i].trOther3 + '"]').prop('selected', 'selected');
                            });
                        }
                        form.render()
                        //添加查阅下载
                        $(".aUploadFile").each(function (i) {
                            var attchId = $(this).attr("attachId");
                            var attchName = $(this).attr("attachName");
                            var div = '<div class="floatDiv" tableName="expect" attchName="' + attchName + '" attchId="' + attchId + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + attchName + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                            $(this).after(div);
                        })
                    }
                });
            }
        }
        $('.add').click(function () {
            var num = $("#ulBox").find("li.layui-this").attr("num");
            var index = $('.layui-this').index();
            var data, url;
            var topicId=$('.add').attr('topicId')
            console.log(topicId)
            flag=1;
            var time1=$('[name="filingTime"]').val();
            switch (index) {
                case 0:
                    if(topicId==undefined){
                        url = '/rpmTopic/insetCertificate'//添加
                        var str = $('#form_basic').serialize()
                            +'&planId=' +planId
                            +'&userId=' +userId
                            +'&ctreateType=3'
                            +'&filingTime='+time1
                        var arr = str.split("&");
                        var str1 = "";
                        for(var i=1;i<arr.length;i++){
                            str1 += arr[i] + "&";
                        }
                        data = str1;
                    }else {
                        url = '/rpmTopic/insetCertificate'//修改
                        var str = $('#form_basic').serialize()
                            +'&planId=' +planId
                            +'&userId=' +userId
                            +'&ctreateType=3'
                            +'&topicId=' +topicId
                            +'&filingTime='+time1
                        var arr = str.split("&");
                        var str1 = "";
                        for(var i=1;i<arr.length;i++){
                            str1 += arr[i] + "&";
                        }
                        data = str1;
                    }
                    break;
                case 1:
                    url = '/rpmTopic/insertSelectiveRemark';
                    var tabpart = table.cache["participator"];
                    for(var i = 0; i < tabpart.length; i++){
                        tabpart[i] = uploadFileReturnTrData(tabpart[i]);
                        tabpart[i].trType=8;
                        delete tabpart[i].files;
                        if ( tabpart[i].topicId == undefined || tabpart[i].topicId == '' ){
                            tabpart[i].topicId = topicId;
                        }
                    }
                    data = {
                        jsonRemark: JSON.stringify(tabpart)
                    }
                    break;
                case 2:
                    url = '/rpmTopic/insertSelectiveRemark'
                    var acad = table.cache["academic"];
                    for(var i = 0; i < acad.length; i++){
                        acad[i] = uploadFileReturnTrData(acad[i]);
                        acad[i].trType=9;
                        delete acad[i].files;
                        if ( acad[i].topicId == undefined || acad[i].topicId == '' ){
                            acad[i].topicId = topicId;
                        }
                    }

                    data = {
                        jsonRemark: JSON.stringify(acad)
                    }
                    break;
                case 3:
                    url = '/rpmTopic/insertSelectiveRemark';
                    var achi = table.cache["achievement"];
                    for(var i = 0; i < achi.length; i++){
                        achi[i] = uploadFileReturnTrData(achi[i]);
                        achi[i].trType=10;
                        delete achi[i].files;
                        if ( achi[i].topicId == undefined || achi[i].topicId == '' ){
                            achi[i].topicId = topicId;
                        }
                    }
                    data = {
                        jsonRemark: JSON.stringify(achi)
                    }
                    break;
                case 4:
                    url = '/rpmTopic/insertSelectiveRemark';
                    var task = table.cache["task"];
                    for(var i = 0; i < task.length; i++){
                        task[i] = uploadFileReturnTrData(task[i]);
                        task[i].trType=11;
                        delete task[i].files;
                        if ( task[i].topicId == undefined || task[i].topicId == '' ){
                            task[i].topicId = topicId;
                        }
                    }
                    data = {
                        jsonRemark: JSON.stringify(task)
                    }
                    break;
                case 5:
                    url = '/rpmTopic/insertSelectiveRemark';
                    var expec = table.cache["expect"];
                    for(var i = 0; i < expec.length; i++){
                        expec[i] = uploadFileReturnTrData(expec[i]);
                        expec[i].trType=12;
                        delete expec[i].files;
                        if ( expec[i].topicId == undefined || expec[i].topicId == '' ){
                            expec[i].topicId = topicId;
                        }
                    }
                    data = {
                        jsonRemark: JSON.stringify(expec)
                    }
                    break;
            }
            $.ajax({
                url: url,
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.flag) {
                        if (data.object != undefined){
                            console.log(data.object)
                            $('.add').attr('topicid',data.object);
                        }
                        tableDatas();
                        layer.msg('保存成功！', {icon: 1}, function () {

                        })
                    } else {
                        layer.msg('保存失败！', {icon: 2});
                    }
                },
                error: function (data) {
                    layer.msg('保存失败！', {icon: 2});
                }
            })

        })
        $("#submit").click(function () {
            var expec = table.cache["expect"];
            for(var i = 0; i < expec.length; i++){
                expec[i] = uploadFileReturnTrData(expec[i]);
                expec[i].trType=12;
                delete expec[i].files;
                if ( expec[i].topicId == undefined || expec[i].topicId == '' ){
                    expec[i].topicId = topicId;
                }
            }
            $.ajax({
                url:'/rpmTopic/insertSelectiveRemark',
                data:{
                    jsonRemark: JSON.stringify(expec)
                },
                type: 'post',
                dataType: 'json',
                success:function(res){
                    if (res.flag) {
                        $.ajax({
                            url:'/rpmTopic/insetCertificate',
                            data:{
                                topicId: topicId,
                                sDirectorLeaderStatus:0
                            },
                            type: 'post',
                            dataType: 'json',
                            success:function(res){
                                if (res.flag) {
                                    layer.msg('保存成功！', {icon: 1}, function () {
                                        window.location.href='/Results/achievementIdentification';
                                    })
                                }else{
                                    layer.msg('保存失败！', {icon: 2});
                                }
                            }
                        })
                    }
                }
            })
        })
        // element.on('tab(edittabbar)', function (data) {
        //     var index = data.index;
        //     switch (index) {
        //         case 1:
        //             if (flag == 0) {
        //                 layer.msg('请保存"基本信息"后，再继续');
        //                 $("#base").click();
        //                 return false;
        //             } else {
        //                 $('#submit').hide()
        //                 $('.add').show()
        //             }
        //             break;
        //         case 2:
        //
        //             if (flag == 0) {
        //                 layer.msg('请保存"基本信息"后，再继续');
        //                 $("#base").click();
        //                 return false;
        //             } else {
        //                 $('#submit').hide()
        //                 $('.add').show()
        //             }
        //             break;
        //         case 3:
        //
        //             if (flag == 0) {
        //                 layer.msg('请保存"基本信息"后，再继续');
        //                 $("#base").click();
        //                 return false;
        //             } else {
        //                 $('#submit').hide()
        //                 $('.add').show()
        //             }
        //             break;
        //         case 4:
        //
        //             if (flag == 0) {
        //                 layer.msg('请保存"基本信息"后，再继续');
        //                 $("#base").click();
        //                 return false;
        //             } else {
        //                 $('#submit').hide()
        //                 $('.add').show()
        //             }
        //             break;
        //         case 5:
        //
        //             if (flag == 0) {
        //                 layer.msg('请保存"基本信息"后，再继续');
        //                 $("#base").click();
        //                 return false;
        //             } else {
        //                 $('#submit').show()
        //                 $('.add').show()
        //             }
        //             break;
        //     }
        // })
        //附件操作区
        $(document).on("mousemove", ".aUploadFile", function () {
            $(".floatDiv").hide();
            $(this).next().show();
        })
        $(document).on("mouseleave ", ".floatDiv", function () {
            $(this).hide();
        })
        //上传并返回行数据需要的attach，放入行数据中返回
        function uploadFileReturnTrData(data) {
            var files = data.files;
            if (files) {
                //创建一个表单数据对象
                var formData = new FormData();
                //得到预存的文件
                for (let key in files) {
                    var file = files[key];
                    //将文件放入同名参数下
                    formData.append('file', file);
                }
                //目录名
                formData.append("module", model);
                $.ajax({
                    url: "/upload",
                    type: 'POST',
                    data: formData,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (res) {
                        //转换json对象，使用eval函数，哪怕res本身是json对象也不会抛异常
                        var resObj = eval('(' + res + ')');
                        //如果上传成功，则开始保存行数据。
                        var objs = resObj.obj;
                        if (objs != undefined && objs.length > 0) {
                            var attachIds = "";
                            var attachNames = "";
                            for (var i = 0; i < objs.length; i++) {
                                var obj = objs[i];
                                attachIds += getAttachIds(obj) + ",";
                                attachNames += obj.attachName + ",";
                            }
                            if (data.attachmentId) {
                                data.attachmentName += "," + attachNames;
                                data.attachmentId += "," + attachIds;
                            } else {
                                data.attachmentName = attachNames;
                                data.attachmentId = attachIds;
                            }
                        }
                        // tableIns.reload();
                    },
                    error: function (data) {
                        alert("失败了！");
                    }
                });

            }
            return data;
        }
        /**
         * 方法介绍:   上传文件初始化
         * 参数说明:   * @param elem 绑定触发上传元素
         * 参数说明:   * @param tableName 表格名称
         * 参数说明:   * @param uploadFeile a标签class
         * @return
         */
        function uploadInit(elem, tableName, uploadFile, attachmentName) {
            upload.render({
                elem: elem
                , accept: "file"
                , auto: false
                , multiple: true
                , choose: function (obj) {
                    var me = this.item;
                    var tabledata = table.cache[tableName]
                    var dataindex = me.parents('tr').attr("data-index");
                    var param = "files";
                    //得到元素
                    var $a = me.parents('tr').find("[data-field='" + attachmentName + "']").eq(0);
                    var $div = $a.children(":first").children(":first");
                    //_____________________-------------------------------------------
                    obj.preview(function (index, file, result) {
                        var param = "files";
                        if (!tabledata[dataindex][param]) {
                            tabledata[dataindex][param] = {};
                        }
                        //针对添加进行处理
                        if (tableName == "participator"||tableName == "academic"||tableName == "achievement"||tableName == "task"||tableName == "expect") {
                            if (!tabledata[dataindex].attachmentName) {
                                tabledata[dataindex].attachmentName = "";
                            }
                            tabledata[dataindex].attachmentName += file.name + ","
                        }
                        tabledata[dataindex][param][index] = file
                        var element = '<a href="javascript:;" file-key="' + index + '" style="color: green" attachId=""  class="layui-table-link ' + uploadFile + '">' + "【" + file.name + "】" + '</a>' +
                            '<div class="floatDiv" tableName="' + tableName + '" attchId="" file-key="' + index + '" style="display: none;overflow: initial"><div class="fileOperation" data-type="docx">' + file.name + '</div><!--<div class="fileOperation" data-type="down">下载</div>--><div data-type="del" class="fileOperation">删除</div></div>'
                        ;
                        $div.append(element);
                    });
                }
            })
        }
        //绑定附件选项点击事件
        $(document).on("click ", ".fileOperation", function () {
            //得到操作栏div
            var parentDiv = $(this).parent();
            //得到附件Id
            var attchId = parentDiv.attr("attchId");
            //得到附件名
            var attchName = parentDiv.attr("attchName");
            //得到操作类别
            var dataType = $(this).attr("data-type");
            //得到layerUI表的id
            var tableName = parentDiv.attr("tableName");
            //得到表数据
            var tabledata = table.cache[tableName]
            //得到当前行索引
            var dataindex = parentDiv.parents('tr').attr("data-index");
            //如果扩展内容打开，会导致行索引获取不到，此处做处理
            if (!dataindex) {
                //必有key
                var fileKey = parentDiv.attr("file-key");
                dataindex = $("[file-key='" + fileKey + "']").parents('tr').eq(0).attr("data-index");
            }
            if (!dataindex) {
                //必有attenid
                var attchid = parentDiv.attr("attchid");
                dataindex = $("[attchid='" + attchid + "']").parents('tr').eq(0).attr("data-index");
            }

            //得到行数据
            var trData = tabledata[dataindex];
            if (trData == undefined) {
                layer.msg("未得到当前行数据")
            } else {
                if (attchId && attchId.length > 0) {
                    //真附件
                    //查看点击的元素
                    switch (dataType) {
                        case "del":
                            layer.confirm('是否确认删除附件？', {icon: 3, title: '提示'}, function (index) {
                                var result = deleteFile(attchId, model);
                                if (result.code == 1) {
                                    layer.confirm('删除附件失败，是否删除关联索引？', {icon: 3, title: '提示'}, function (index) {
                                        trData = spliceAttach(trData, attchId)
                                        delete trData.files;
                                        save(trData)
                                    })
                                } else {
                                    trData = spliceAttach(trData, attchId)
                                    delete trData.files;
                                    save(trData);
                                }
                            })
                            break;

                        case "down":
                            window.location.href = "/limsFile/limsDownload?model=" + model + "&attachId=" + attchId
                            break;
                        case "docx":
                            selectFile(attchId, model);
                    }
                } else {
                    //假附件 得到key
                    var fileKey = parentDiv.attr("file-key");
                    //查看点击的元素
                    switch (dataType) {
                        case "del":
                            delete trData["files"][fileKey];
                            $("[file-key='" + fileKey + "']").remove();
                            break;
                    }
                }
            }


        })
    });
    function nowformat() {
        var nstr = "";
        var now = new Date();
        var nyear = now.getFullYear();
        var nmonth = now.getMonth() + 1;
        var nday = now.getDate();
        if (nmonth < 10) {
            nmonth = "0" + nmonth;
        }
        if (nday < 10) {
            nday = "0" + nday;
        }
        nstr = nyear + "-" + nmonth + "-" + nday;
        return nstr;
    }
    function getAttachIds(obj) {
        return obj.aid+"@"+obj.ym+"_"+obj.attachId;
    }
</script>
